package leetcode;

import java.util.Stack;

/**
 * Created by Ghost on 2014/10/31 0031.
 */
public class Simplify_Path {
    public String simplifyPath(String path) {
        Stack<String> stack = new Stack<String>();
        String[] paths = path.split("/");
        for(String ch:paths){
            if(ch.length()==0) {
            }
            else if(ch.equals("..")){
                if(stack.empty()) {
                }
                else
                    stack.pop();
            }
            else if(ch.equals(".")){
            }
            else
                stack.push(ch);
        }
        if(stack.empty())
            return "/";
        else{
            String rst = "";
            while(!stack.empty()){
                rst = "/"+stack.pop()+rst;
            }
            return rst;
        }
    }
    public static void main(String[] args){
        Simplify_Path simplify_path = new Simplify_Path();
        System.out.println(simplify_path.simplifyPath("/home/.../hehe/../../slslls/"));
    }
}
